<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>医家管理平台</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <style type="text/css">
        #tianjiabanbenkongzhiNav{
            position: relative;
        }
        #tianjiabanbenkongzhiBtn{
            float: right;
            margin-bottom: 20px;
            margin-right: 30px;
        }
        #yama{
            float: left;
            margin-left: 30px;
            margin-top: 0px;
        }
    </style>
</head>
<body>
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/home">医家管理平台</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li <%= azhzdmoban%>><a id = "azhzdbbkz">安卓患者端</a></li>
                <li <%= azysdmoban%>><a id = "azysdbbkz">安卓医生端</a></li>
                <li <%= ioshzdmoban%>><a id = "ioshzdbbkz">IOS患者端</a></li>
                <li <%= iosysdmoban%>><a id = "iosysdbbkz">IOS医生端</a></li>
            </ul>
        </div>
    </div><!-- /.container-fluid -->
</nav>
<nav id = "tianjiabanbenkongzhiNav">
    <button type="button" class="btn btn-primary btn-sm" id = "tianjiabanbenkongzhiBtn" data-toggle="modal" data-target="#banbenkongzhiModal">添加版本控制</button>
    <ul class="pagination" id="yama">
        <li class="active"><a href="#">1 <span class="sr-only">(current)</span></a></li>
        <li><a href="#">2 <span class="sr-only">(current)</span></a></li>
        <li><a href="#">3 <span class="sr-only">(current)</span></a></li>
    </ul>
</nav>
<div class="container">
    <!-- Main component for a primary marketing message or call to action -->
    <!--<div class="jumbotron">-->
    <table class="table table-bordered table-striped js-options-table">
        <thead>
        <tr>
            <th>版本号</th>
            <th>强制更新版本号</th>
            <th>标题</th>
            <th>内容</th>
            <th>下载地址</th>
            <th>时间</th>
        </tr>
        </thead>
        <tbody id="liebiaodiv">
        <tr>
            <td>backdrop</td>
            <td>boolean 或 字符串 <code>'static'</code></td>
            <td>true</td>
            <td>Includes a modal-backdrop element. Alternatively, specify <code>static</code> for a backdrop which doesn't close the modal on click.</td>
            <td>www.baidu.com</td>
            <td>2012/2/2</td>
        </tr>
        </tbody>
    </table>

    <!-- Modal -->
    <div class="modal fade" id="banbenkongzhiModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">添加版本控制</h4>
                </div>
                <div class="modal-body">
                    <div class="input-group">
                        <span class="input-group-addon banbengenxingInput" id="sizing-addon2">最新版本号</span>
                        <input type="text" class="form-control" aria-describedby="sizing-addon2" id="zuixin"
                               onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)" onblur="this.v();">
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon banbengenxingInput" id="sizing-addon2">强制升级版本号</span>
                        <input type="text" class="form-control" aria-describedby="sizing-addon2" id="qiangzhi"
                               onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)" onblur="this.v();">
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon banbengenxingInput" id="sizing-addon2">标题</span>
                        <input type="text" class="form-control" aria-describedby="sizing-addon2" id="title">
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon banbengenxingInput" id="sizing-addon2">内容</span>
                        <input type="text" class="form-control" aria-describedby="sizing-addon2" id="content">
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon banbengenxingInput" id="sizing-addon2">下载地址</span>
                        <input type="text" class="form-control" aria-describedby="sizing-addon2" id="appUrl"
                               placeholder="填入正规的http://开头的下载地址,否者会APP会崩溃">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" data-dismiss="modal" id="modelQueding">确定</button>
                </div>
            </div>
        </div>
    </div>

</div> <!-- /container -->
<script type="text/template" id="liebiaomoban">
    <tr>
        <td>{{= banbenhaomoban}}</td>
        <td>{{= qiangzhimoban}}</td>
        <td>{{= biaotimoban}}</td>
        <td>{{= neirongmoban}}</td>
        <td>{{= dizhimoban}}</td>
        <td>{{= shijianmoban}}</td>
    </tr>
</script>

<script type="text/javascript" src="js/underscore-noflect.js"></script>
<script src="js/jquery-1.11.3.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
    //获取数据
    var nowpage = 1;
    getData(1);
    function getData(page) {
        //取出问号的值
        var appIdd = Number(location.search.substring(1));
        $.post('/node/takeBbkz',{
            'page' : page,
            'appId' : appIdd
        },function (result) {
            //得到模板，弄成模板函数
            var compiled = _.template($("#liebiaomoban").html());
            //清空列表所有节点
            $("#liebiaodiv").html("");
            console.log(result);
            for (var i = 0 ; i < result.length; i++){
                //数据绑定
                var date = new Date(result[i].date);
                var dateStr =  date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
                var html = compiled({
                    banbenhaomoban: result[i].zuixin,
                    qiangzhimoban: result[i].qiangzhi,
                    neirongmoban: result[i].content,
                    biaotimoban: result[i].title,
                    dizhimoban: result[i].appUrl,
                    shijianmoban:dateStr
                });
                $('#liebiaodiv').append($(html));
            }
        });
    }
    //获取url中的参数
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg);  //匹配目标参数
        if (r != null) return unescape(r[2]); return null; //返回参数值
    }
    //安卓患者端版本控制
    $('#azhzdbbkz').on('click', function () {
        $.post('node/bbkz',{
            'appId' : 1
        },function (result) {
            if (result.isSucceed == '1') {
                location.href = result.url;
            }
        });
    })
    //安卓医生端版本控制
    $('#azysdbbkz').on('click', function () {
        $.post('node/bbkz',{
            'appId' : 2
        },function (result) {
            if (result.isSucceed == '1') {
                location.href = result.url;
            }
        });
    })
    //ios患者端版本控制
    $('#ioshzdbbkz').on('click', function () {
        $.post('node/bbkz',{
            'appId' : 3
        },function (result) {
            if (result.isSucceed == '1') {
                location.href = result.url;
            }
        });
    })
    //ios医生端版本控制
    $('#iosysdbbkz').on('click', function () {
        $.post('node/bbkz',{
            'appId' : 4
        },function (result) {
            if (result.isSucceed == '1') {
                location.href = result.url;
            }
        });
    })
    //点击model中的确定按钮
    $('#modelQueding').on('click',function () {
        console.log($('#title'));
        //取出问号的值
        var appIdd = Number(location.search.substring(1));
        $.post('node/yjysd/addBangBen',{
            'appId' : appIdd,
            'title' : $('#title').val(),
            'content':$('#content').val(),
            'qiangzhi' : $('#qiangzhi').val(),
            'zuixin' : $('#zuixin').val(),
            'appUrl':$('#appUrl').val(),
            'date':new Date()
        },function (result) {
            window.location.reload();//刷新当前页面.
        });
    })
</script>
</body>
</html>